package com.itheima.servlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/demo12")
public class ServletDemo12 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        System.out.println("demo12执行了");
        //servlet跳转servlet

        //请求转发          //指定跳转路径
        req.getRequestDispatcher("/demo13").forward(req,resp);

        //作用域 全局作用域 ServletContext
        ServletContext sc = getServletContext();
        //设置作用域数据
        //全局作用域数据 重定向
        sc.setAttribute("username","zhangsan");
        //全局作用域数据  请求对象和重定向都可以带值
        resp.sendRedirect(req.getContextPath()+"/demo13");
    }
}
